// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.network.packets;

import java.nio.ByteBuffer;
import zombie.characters.IsoPlayer;
import zombie.core.network.ByteBufferWriter;
import zombie.core.raknet.UdpConnection;
import zombie.network.GameClient;
import zombie.network.GameServer;

public class SyncInjuriesPacket implements INetworkPacket {
    public short id;
    public float strafeSpeed;
    public float walkSpeed;
    public float walkInjury;
    public IsoPlayer player;

    public boolean set(IsoPlayer _player) {
        if (GameClient.bClient) {
            this.id = (short)_player.getPlayerNum();
        } else if (GameServer.bServer) {
            this.id = _player.getOnlineID();
        }

        this.strafeSpeed = _player.getVariableFloat("StrafeSpeed", 1.0F);
        this.walkSpeed = _player.getVariableFloat("WalkSpeed", 1.0F);
        this.walkInjury = _player.getVariableFloat("WalkInjury", 0.0F);
        this.player = _player;
        return true;
    }

    public boolean process() {
        if (this.player != null && !this.player.isLocalPlayer()) {
            this.player.setVariable("StrafeSpeed", this.strafeSpeed);
            this.player.setVariable("WalkSpeed", this.walkSpeed);
            this.player.setVariable("WalkInjury", this.walkInjury);
            return true;
        } else {
            return false;
        }
    }

    @Override
    public void parse(ByteBuffer b, UdpConnection connection) {
        this.id = b.getShort();
        this.strafeSpeed = b.getFloat();
        this.walkSpeed = b.getFloat();
        this.walkInjury = b.getFloat();
        if (GameServer.bServer) {
            this.player = GameServer.getPlayerFromConnection(connection, this.id);
        } else if (GameClient.bClient) {
            this.player = (IsoPlayer)GameClient.IDToPlayerMap.get(this.id);
        } else {
            this.player = null;
        }
    }

    @Override
    public void write(ByteBufferWriter b) {
        b.putShort(this.id);
        b.putFloat(this.strafeSpeed);
        b.putFloat(this.walkSpeed);
        b.putFloat(this.walkInjury);
    }

    @Override
    public int getPacketSizeBytes() {
        return 14;
    }

    @Override
    public String getDescription() {
        return "SyncInjuriesPacket: id=" + this.id + ", strafeSpeed=" + this.strafeSpeed + ", walkSpeed=" + this.walkSpeed + ", walkInjury=" + this.walkInjury;
    }
}
